using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Reflection;

namespace ZX.BLL.ClientMobi.Message
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class Code_BaseInfoInfo
    {
        #region 属性
        private string _baseCode = "";
        /// <summary>
        /// 记录编号
        /// </summary>
        public string BaseCode
        {
            get{return _baseCode;}
            set{_baseCode = value;}
        }
        
        private string _catNO = "";
        /// <summary>
        /// 类别编号[关联表Code_CategoryInfo的CatNO字段]
        /// </summary>
        public string CatNO
        {
            get{return _catNO;}
            set{_catNO = value;}
        }
        
        private string _codeNO = "";
        /// <summary>
        /// 编码编号
        /// </summary>
        public string CodeNO
        {
            get{return _codeNO;}
            set{_codeNO = value;}
        }
        
        private string _codeName = "";
        /// <summary>
        /// 编码名称
        /// </summary>
        public string CodeName
        {
            get{return _codeName;}
            set{_codeName = value;}
        }
        
        private string _pCodeNO = "";
        /// <summary>
        /// 上级编码编号[第一级时为空值]
        /// </summary>
        public string PCodeNO
        {
            get{return _pCodeNO;}
            set{_pCodeNO = value;}
        }
        
        private int _orderNO = 0;
        /// <summary>
        /// 权重编号 [数值越大越靠前]
        /// </summary>
        public int OrderNO
        {
            get{return _orderNO;}
            set{_orderNO = value;}
        }
        
        private string _remark = "";
        /// <summary>
        /// 备注
        /// </summary>
        public string Remark
        {
            get{return _remark;}
            set{_remark = value;}
        }
        
        private string _isValid = "";
        /// <summary>
        /// 是否有效[0：否，1：是]
        /// </summary>
        public string IsValid
        {
            get{return _isValid;}
            set{_isValid = value;}
        }

        private string _cx = "";
        public string cx {
            get { return _cx; }
            set { _cx = value; }
        }

        
        #endregion
        
        #region 构造函数
        public Code_BaseInfoInfo()
        {}
        
        public Code_BaseInfoInfo
        (
            string baseCode,
            string catNO,
            string codeNO,
            string codeName,
            string pCodeNO,
            int orderNO,
            string remark,
            string isValid,
            string cx
        )
        {
            _baseCode = baseCode;
            _catNO = catNO;
            _codeNO = codeNO;
            _codeName = codeName;
            _pCodeNO = pCodeNO;
            _orderNO = orderNO;
            _remark = remark;
            _isValid = isValid;
            _cx = cx;
        }
        #endregion
        
        #region 填充数据实体
        /// <summary>
        /// 得到Code_BaseInfoInfo数据实体
        /// </summary>
        /// <param name="row">row</param>
        /// <returns>Code_BaseInfoInfo数据实体</returns>
        public static Code_BaseInfoInfo PopulateFromDataRow(DataRow row)
        {
            Code_BaseInfoInfo obj = new Code_BaseInfoInfo();
            if (row != null)
            {
                obj.BaseCode = row["BaseCode"] == DBNull.Value ? "" : Convert.ToString(row["BaseCode"]);   
                obj.CatNO = row["CatNO"] == DBNull.Value ? "" : Convert.ToString(row["CatNO"]);   
                obj.CodeNO = row["CodeNO"] == DBNull.Value ? "" : Convert.ToString(row["CodeNO"]);   
                obj.CodeName = row["CodeName"] == DBNull.Value ? "" : Convert.ToString(row["CodeName"]);   
                obj.PCodeNO = row["PCodeNO"] == DBNull.Value ? "" : Convert.ToString(row["PCodeNO"]);   
                obj.OrderNO = row["OrderNO"] == DBNull.Value ? 0 : Convert.ToInt32(row["OrderNO"]);   
                obj.Remark = row["Remark"] == DBNull.Value ? "" : Convert.ToString(row["Remark"]);   
                obj.IsValid = row["IsValid"] == DBNull.Value ? "" : Convert.ToString(row["IsValid"]);
                obj.cx = row["cx"] == DBNull.Value ? "" : Convert.ToString(row["cx"]);
            }
            else
            {
                return null;
            }
            return obj;
        }
        
        /// <summary>
        /// 得到Code_BaseInfoInfo数据实体
        /// </summary>
        /// <param name="reader">reader</param>
        /// <returns>Code_BaseInfoInfo数据实体</returns>
        public static Code_BaseInfoInfo PopulateFromReader(IDataReader reader)
        {
            Code_BaseInfoInfo obj = new Code_BaseInfoInfo();
            
            obj.BaseCode = reader["BaseCode"] == DBNull.Value ? "" : Convert.ToString(reader["BaseCode"]);
            obj.CatNO = reader["CatNO"] == DBNull.Value ? "" : Convert.ToString(reader["CatNO"]);
            obj.CodeNO = reader["CodeNO"] == DBNull.Value ? "" : Convert.ToString(reader["CodeNO"]);
            obj.CodeName = reader["CodeName"] == DBNull.Value ? "" : Convert.ToString(reader["CodeName"]);
            obj.PCodeNO = reader["PCodeNO"] == DBNull.Value ? "" : Convert.ToString(reader["PCodeNO"]);
            obj.OrderNO = reader["OrderNO"] == DBNull.Value ? 0 : Convert.ToInt32(reader["OrderNO"]);
            obj.Remark = reader["Remark"] == DBNull.Value ? "" : Convert.ToString(reader["Remark"]);
            obj.IsValid = reader["IsValid"] == DBNull.Value ? "" : Convert.ToString(reader["IsValid"]);
            obj.cx = reader["cx"] == DBNull.Value ? "" : Convert.ToString(reader["cx"]);
            return obj;
        }
        
        /// <summary>
        /// 得到Code_BaseInfo，DataTable
        /// </summary>
        /// <param name="info">info</param>
        /// <returns>Code_BaseInfo，DataTable</returns>
        public static DataTable PopulateFromInfo(Code_BaseInfoInfo info)
        {
            DataTable table = new DataTable("Code_BaseInfo");
            DataRow row = null;
            
            if (info != null)
            {
                
                table.Columns.Add("BaseCode", typeof(string));
                table.Columns.Add("CatNO", typeof(string));
                table.Columns.Add("CodeNO", typeof(string));
                table.Columns.Add("CodeName", typeof(string));
                table.Columns.Add("PCodeNO", typeof(string));
                table.Columns.Add("OrderNO", typeof(int));
                table.Columns.Add("Remark", typeof(string));
                table.Columns.Add("IsValid", typeof(string));
                table.Columns.Add("cx", typeof(string));
            
                row = table.NewRow();
            
                row["BaseCode"] = info.BaseCode;
                row["CatNO"] = info.CatNO;
                row["CodeNO"] = info.CodeNO;
                row["CodeName"] = info.CodeName;
                row["PCodeNO"] = info.PCodeNO;
                row["OrderNO"] = info.OrderNO;
                row["Remark"] = info.Remark;
                row["IsValid"] = info.IsValid;
                row["cx"] = info.IsValid;

                table.Rows.Add(row);
            }

            return table;
        }
        
        /// <summary>
        /// 得到Code_BaseInfo，DataTable
        /// </summary>
        /// <param name="infoList">infoList</param>
        /// <returns>Code_BaseInfo，DataTable</returns>
        public static DataTable PopulateFromInfoList(List< Code_BaseInfoInfo> infoList)
        {
            DataTable table = new DataTable("Code_BaseInfo");
            DataRow row = null;
            
            if (infoList != null)
            {
                
                table.Columns.Add("BaseCode", typeof(string));
                table.Columns.Add("CatNO", typeof(string));
                table.Columns.Add("CodeNO", typeof(string));
                table.Columns.Add("CodeName", typeof(string));
                table.Columns.Add("PCodeNO", typeof(string));
                table.Columns.Add("OrderNO", typeof(int));
                table.Columns.Add("Remark", typeof(string));
                table.Columns.Add("IsValid", typeof(string));
                table.Columns.Add("cx", typeof(string));
                
                for(int i = 0; i < infoList.Count; i++)
                {
                    row = table.NewRow();
                
                    row["BaseCode"] = infoList[i].BaseCode;
                    row["CatNO"] = infoList[i].CatNO;
                    row["CodeNO"] = infoList[i].CodeNO;
                    row["CodeName"] = infoList[i].CodeName;
                    row["PCodeNO"] = infoList[i].PCodeNO;
                    row["OrderNO"] = infoList[i].OrderNO;
                    row["Remark"] = infoList[i].Remark;
                    row["IsValid"] = infoList[i].IsValid;
                    row["cx"] = infoList[i].cx;

                    table.Rows.Add(row);
                }
            }

            return table;
        }
        
        /// <summary>
        /// Copy得到Code_BaseInfoInfo，对象
        /// </summary>
        /// <param name="data">data</param>
        /// <returns>Code_BaseInfo，对象</returns>
        public static Code_BaseInfoInfo CopyData<T>(T data) where T : class
        {
            if (data == null) return null;
            
            Code_BaseInfoInfo info = new Code_BaseInfoInfo();
            PropertyInfo[] infoProList = info.GetType().GetProperties();
            PropertyInfo[] dataProList = data.GetType().GetProperties();
            
            foreach (PropertyInfo infoPro in infoProList)
            {
                foreach (PropertyInfo dataPro in dataProList)
                {
                    if (infoPro.Name == dataPro.Name && infoPro.PropertyType.FullName == dataPro.PropertyType.FullName)
                    {
                        infoPro.SetValue(info, dataPro.GetValue(data, null), null);
                    }
                }
            }
            
            return info;
        }
        
        #endregion
    }
}


